'''
Created on 31/07/2011

@author: Digao
'''
import re
def toInt(arg):
    return int(arg)

def toStr(a,b):
    return str(a)+' '+str(b)
def main():

    input = open('input.in')
    L,D,N = map(toInt,input.readline().strip().split(' '))
    dict = {}
    for i in range(D):
        dict[input.readline().strip()]=1
    for case in range(1,N+1):
        pat = input.readline().strip().replace('(','[').replace(')',']')
        reg = re.compile(pat)
        found = [it for it in dict if reg.match(it)]
        ans = 'Case #%d: %s'%(case,len(found))
        print ans


if __name__ == '__main__':
    main()
